<template>
  <!--会签管理-我的提交列表-付款计划编辑弹窗-->
  <j-modal :title="title" :width="width" :visible="visible" switchFullscreen @ok="handleOk" @cancel="handleCancel"
    okText="提交">
    <!-- <a-popconfirm confirmText="确定"
					cancelText="取消"
					@cancel="cancelPrivacy"
					@confirm="confirmPrivacy" :disabled="privacyDialogShow"  title="确定提交吗？" >
      </a-popconfirm> -->
    <template v-if="pageType === 'edit'">
      <wt-weitijiao-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit"></wt-weitijiao-form>
    </template>
    <template v-else-if="pageType === 'anew'">
      <a-tabs type="card" @change="callback">
        <a-tab-pane key="1" tab="重新提交">
          <wt-weitijiao-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit"></wt-weitijiao-form>
        </a-tab-pane>
        <a-tab-pane key="2" tab="查看上次审核记录">
          <wt-jihua-form ref="realForm2" :disabled="disableSubmit2"></wt-jihua-form>
        </a-tab-pane>
      </a-tabs>
    </template>
    <template #footer>
      <a-button  key="back" @click="handleCancel">取消</a-button>
      <a-popconfirm v-if="pageType != 'anew'" title="确定保存吗？" @confirm="handleSave"><a-button key="save" type="primary" >保存</a-button></a-popconfirm>
      <a-popconfirm  title="确定提交吗？" @confirm="handleOk"><a-button key="submit" type="primary">提交</a-button></a-popconfirm>
    </template>
  </j-modal>
</template>
<script>
  import WtWeitijiaoForm from './WtWeitijiaoForm'
  import WtJihuaForm from './WtJihuaForm'
  export default {
    name: 'WtShenpiModal',
    components: {
      WtWeitijiaoForm,
      WtJihuaForm

    },
    data() {
      return {
        title: '',
        width: 1000,
        visible: false,
        disableSubmit: false,
        disableSubmit2: false,
        privacyDialogShow: false,
        pageType: '', //anew-重复提交 edit-编辑
        objdata: {},
      }
    },
    methods: {
      callback(e) {
        console.log(1, e)
        if (e === '2') {
          this.$nextTick(() => {
            this.$refs.realForm2.edit(this.objdata);
            this.disableSubmit2 = true;
          })
        }
      },
      confirmPrivacy() {
        // console.log('同意了用户协议')
        // console.log(this.privacyDialogShow)l
        this.privacyDialogShow = false
        // console.log(this.privacyDialogShow)

      },
      cancelPrivacy() {
        // console.log('拒绝了用户协议')
        this.privacyDialogShow = false
      },
      add() {
        this.visible = true
        this.$nextTick(() => {
          this.$refs.realForm.add();
        })
      },
      edit(record, type) {
        let that = this;
        this.objdata = record;
        if (!!type) {
          this.pageType = type;
        }
        this.visible = true;
        this.$nextTick(() => {
          this.$refs.realForm.edit(record, type);
        })
        this.$forceUpdate();
      },
      close() {
        this.$emit('close');
        this.visible = false;
      },
      handleOk() {
        this.$refs.realForm.submitForm('1');
      },
      handleSave() {
        this.$refs.realForm.submitForm('0')
      },
      submitCallback() {
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel() {
        this.close()
      }
    }
  }
</script>